﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScriptWeb.control;

namespace MixScriptWeb.Jideco.WM
{
    public partial class MOFrpt : System.Web.UI.Page
    {
        private static DateTime tglPO;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                tglPO = DateTime.Now;
                txtDate1.Text = tglPO.ToString("dd-MM-yyyy");
                txtDate2.Text = tglPO.ToString("dd-MM-yyyy");
                addFindClickAttribute(this, new MixScriptTB[] { txtMOF }, new string[] { "SRCMOFRPT"});
            }
        }
        public void addFindClickAttribute(Page p, MixScriptTB[] mtb, string[] searchid)
        {
            try
            {
                int i = 0;
                if (mtb.Length != searchid.Length)
                    throw new Exception("The number searchid must in the same with control");
                foreach (MixScriptTB m in mtb)
                {
                    System.Web.UI.WebControls.Image im = (System.Web.UI.WebControls.Image)m.FindControl("imgFind");
                    im.Attributes.Add("onclick", "return browseitem('" + p.Form.ClientID + "', '" + m.ClientID + "_txt','" + m.ClientID + "_lbl','" + searchid[i] + "');");
                    i++;

                }
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtMOF.Text = "";
        }

        protected void btnReport_Click(object sender, EventArgs e)
        {
            Session["smofno"] = txtMOF.Text;
            Session["sawalm"] = txtDate1.Text.Substring(6, 4) + "-" + txtDate1.Text.Substring(3, 2) + "-" + txtDate1.Text.Substring(0, 2) + " 00:00:00";
            Session["sakhirm"] = txtDate2.Text.Substring(6, 4) + "-" + txtDate2.Text.Substring(3, 2) + "-" + txtDate2.Text.Substring(0, 2) + " 23:59:59";

            string sscript = "";
            sscript += "<script>";
            sscript += "window.open('../print/rptid-9,smofno-" + "" + ",suppid-" + "" + ",dl.html', '_blank');";
            sscript += "</script>";
            ClientScript.RegisterStartupScript(GetType(), "report", sscript);            
        }
    }
}